﻿Imports System.Linq
Imports System.Data.SqlClient
Imports System.Collections.Generic
Imports SISSAT.BusinessLayer.DomainModels
Imports SISSAT.DataAcessLayer.StatementSources
Imports SISSAT.DataAcessLayer.PersistentStorage
Imports SISSAT.BusinessLayer.Utilities

Namespace Services
    Public Class EmployeeTypeService
        Inherits ServiceBase
        Implements IEmployeeTypeService

        Public Sub Create(name As String, description As String, createdBy As Integer) Implements IEmployeeTypeService.Create
            StatementSource = New CreateEmployeeTypeStatementSource(name, description, createdBy)
            Dim nonQuery As Integer = DbHelper.ExecuteNonQuery(StatementSource)
        End Sub

        Public Sub Delete(employeeTypeId As Integer) Implements IEmployeeTypeService.Delete
            StatementSource = New DeleteEmployeeTypeStatementSource(employeeTypeId)
            Dim nonQuery As Integer = DbHelper.ExecuteNonQuery(StatementSource)
        End Sub

        Public Sub Edit(entity As EmployeeType, modifiedBy As Integer) Implements IEmployeeTypeService.Edit
            StatementSource = New UpdateEmployeeTypeStatementSource(entity.EmployeeTypeId, entity.Name, entity.Description, modifiedBy)
            Dim nonQuery As Integer = DbHelper.ExecuteNonQuery(StatementSource)
        End Sub

        Public Function ReadAll() As System.Collections.Generic.IEnumerable(Of EmployeeType) Implements IEmployeeTypeService.ReadAll
            StatementSource = New ReadAllEmployeeTypeStatementSource()
            Dim dataReader As SqlDataReader = DbHelper.ExecuteReader(StatementSource)

            Return DataMapper.MapDataToEntity(Of EmployeeType)(dataReader)
        End Function

        Public Function ReadById(employeeTypeId As Integer) As EmployeeType Implements IEmployeeTypeService.ReadById
            StatementSource = New ReadByEmployeeTypeIdStatementSource(employeeTypeId)
            Dim dataReader As SqlDataReader = DbHelper.ExecuteReader(StatementSource)

            Return DataMapper.MapDataToEntity(Of EmployeeType)(dataReader).FirstOrDefault()
        End Function
    End Class
End Namespace

